package com.thl.processService;

import com.thl.common.enums.BusinessScene;
import com.thl.common.enums.ServiceDescription;
import com.thl.dto.ServiceContext;
import com.thl.process.AbstractExecuteService;
import com.thl.process.BaseProcessor;
import com.thl.process.ProcessorServiceContext;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 1900614@qq.com
 * @version 1.0
 * @date 2021/6/19 19:57
 */
@Service
public class MyService  extends AbstractExecuteService {

    @Override
    public void execute(ServiceContext serviceContext) {
        processor(serviceContext,ServiceDescription.SELL);
        processor(serviceContext,ServiceDescription.AFTER_SALE);

    }

    final  void processor(ServiceContext serviceContext, ServiceDescription serviceDescription){
        List<BaseProcessor> processors = ProcessorServiceContext.baseProcessors(serviceContext, serviceDescription);
        if(CollectionUtils.isNotEmpty(processors)){
            processors.stream().filter(p->null!=p).forEach(p->p.execute(serviceContext));
        }
    }
}
